package com.micro.school.order.util;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Random;
import java.util.concurrent.atomic.AtomicInteger;

public class OrderNoGenerator {

    private static final String PREFIX = "ORD"; // 业务前缀：ORD=订单，REF=退款等
    private static final String PAY_PREFIX = "PAY"; // 支付单
    private static final String REFUND_PREFIX = "RFD";

    private static final AtomicInteger counter = new AtomicInteger(0);

    /**
     * 生成支付单号
     */
    public static String generatePayNo() {
        int value = counter.getAndIncrement() % 1000;
        String seq = String.format("%03d", value);
        return PAY_PREFIX + LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyyMMddHHmmss")) + seq;
    }

    public static String generateOrderNo() {
        int value = counter.getAndIncrement() % 1000;
        String seq = String.format("%03d", value);
        return PREFIX + LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyyMMddHHmmss")) + seq;
    }
}